# from django.shortcuts import render,HttpResponse,redirect
# from app01.models import Parents
# # 创建一条父母数据
# from app01.models import Student
# from app01 import models
# from app01.utils import pagination
# def stu_list(request):
#     # data_list = Student.objects.all()
#     # print(data_list)
#     # return render(request,"info_list.html",{"data_list":data_list})
#     queryset = models.Student.objects.all()
#     pag_obj = pagination.Pagination(request,queryset)
#     context = {
#         "queryset": pag_obj.page_queryset,
#         "page_string": pag_obj.html(),
#     }
#     return render(request, 'stu_list.html',context)

# from django import forms


# class StuModelForm(forms.ModelForm):
#     name = forms.CharField(min_length=3, label="用户名")

#     class Meta:
#         model = models.Student
#         fields = ["name", "age", "gender", 'student_id', 'classroom', "birthday","portrait_url","head_teacher","guardians"]
#         # widgets = {
#         #     "name": forms.TextInput(attrs={"class": "form-control"}),
#         #     "password": forms.PasswordInput(attrs={"class": "form-control"}),
#         #     "age": forms.TextInput(attrs={"class": "form-control"}),
#         # }

#     def __init__(self, *args, **kwargs):
#         super().__init__(*args, **kwargs)
#         # 循环找到所有的插件，添加了class="form-control"
#         for name, field in self.fields.items():
#             # if name == "password":
#             #     continue
#             field.widget.attrs = {"class": "form-control", "placeholder": field.label}
# def user_model_form_add(request):
#     """ 添加用户（ModelForm版本）"""
#     if request.method == "GET":
#         form = StuModelForm()
#         return render(request, 'user_model_form_add.html', {"form": form})

#     # 用户POST提交数据，数据校验。
#     form = StuModelForm(data=request.POST)
#     if form.is_valid():  # dajianggo自动进行数据校验

#         # 如果数据合法，保存到数据库
#         # {'name': '123', 'password': '123', 'age': 11, 'account': Decimal('0'), 'create_time': datetime.datetime(2011, 11, 11, 0, 0, tzinfo=<UTC>), 'gender': 1, 'depart': <Department: IT运维部门>}
#         # print(form.cleaned_data)
#         # models.UserInfo.objects.create(..)
#         form.save()
#         return redirect('/xybl/stu_list/')

#     # 校验失败（在页面上显示错误信息）
#     return render(request, 'stu_add.html', {"form": form})  # 与上面的form是不一样的，它会有验证失败之后的错误信息
# from app01.models import Classroom
# from app01.models import Psychologist, Classroom

# # 先获取人工智能 221 班级对象

# def stu_add(request):
#     # classroom = Classroom.objects.get(class_name="人工智能 222")
#     # # #
#     # # # # 创建并插入心理辅导老师信息
#     # psychologist = Psychologist(name="李老师", responsible_classes=classroom)
#     # psychologist.save()
#     # 创建并保存班级信息
#     # classroom = Classroom(class_name="人工智能 222")
#     # classroom.save()
#     # parent = Parents(name="张三", age=40, relation_to_student="FATHER")
#     # parent.save()
#     """ 添加学生"""
#     if request.method == "GET":
#         form = StuModelForm()
#         return render(request, 'stu_add.html', {"form": form})
#     # 用户POST提交数据，数据校验。
#     form = StuModelForm(data=request.POST)
#     if form.is_valid():  # dajianggo自动进行数据校验

#         # 如果数据合法，保存到数据库
#         # {'name': '123', 'password': '123', 'age': 11, 'account': Decimal('0'), 'create_time': datetime.datetime(2011, 11, 11, 0, 0, tzinfo=<UTC>), 'gender': 1, 'depart': <Department: IT运维部门>}
#         # print(form.cleaned_data)
#         # models.UserInfo.objects.create(..)
#         form.save()
#         return redirect('/xybl/stu_list/')
#     # 校验失败（在页面上显示错误信息）
#     return render(request, 'stu_add.html', {"form": form})  # 与上面的form是不一样的，它会有验证失败之后的错误信息
